package com.zzyl.common.utils;

import lombok.extern.slf4j.Slf4j;

/**
 * 小程序绑定到ThreadLocal的工具类
 *  用户主体对象
 * @author ghy
 */
@Slf4j
public class MemberThreadLocal {

    private static final ThreadLocal<Long> LOCAL = new ThreadLocal<>();

    private MemberThreadLocal() {}

    /**
     * 将memberId放到ThreadLocal中
     *
     * @param memberId {@link Long}
     */
    public static void setMemberId(Long memberId) {
        LOCAL.set(memberId);
    }

    /**
     * 从当前线程中删除memberId
     */
    public static void remove() {
        LOCAL.remove();
    }

    /**
     * 从当前线程中获取前端用户id
     * @return 用户id
     */
    public static Long getMemberId() {
        return LOCAL.get();
    }


}
